package co.fitstart.admin.dao;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dynamic;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;

import co.fitstart.entity.site.Site;
import co.fitstart.entity.user.UserSource;
import co.fitstart.entity.user.UserSourceStatus;

/**
 * 
 * @author mohanlan
 *
 */
@Dynamic("hibernate")
public interface UserSourceDao {
	
	/**
     * 
     * @param site
     * @param courseType
     * @param courseStatus
     * @param experience
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM UserSource userSource WHERE userSource.userSourceStatus = :userSourceStatus AND userSource.disabled = false ORDER BY createTime DESC")
    public List<UserSource> listUserSource(@Variable("userSourceStatus") UserSourceStatus userSourceStatus, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
	
	/**
     * 
     * @param site
     * @param courseType
     * @param courseStatus
     * @param experience
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM UserSource userSource WHERE userSource.userSourceStatus = :userSourceStatus AND userSource.disabled = false AND userSource.site = :site ORDER BY createTime DESC")
    public List<UserSource> listUserSource(@Variable("userSourceStatus") UserSourceStatus userSourceStatus, @Variable("site") Site site, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    
    @Limit
    @Query("FROM UserSource userSource WHERE userSource.userSourceStatus = :userSourceStatus AND userSource.disabled = false AND userSource.site in (:sites) ORDER BY createTime DESC")
    public List<UserSource> listUserSource(@Variable("userSourceStatus") UserSourceStatus userSourceStatus, @Variable("sites") List<Site> sites, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param mobile
     * @return
     */
    @Query("FROM UserSource userSource WHERE userSource.disabled = false AND userSource.mobile = :mobile")
    public UserSource load(@Variable("mobile") String mobile);

}
